'use strict';

/* 
必读：
uni-ai 开发文档：https://en.uniapp.dcloud.io/uniCloud/uni-ai.html 
uni-ai计费网关开通流程 ：https://en.uniapp.dcloud.io/uniCloud/uni-ai-buy.html#enable-uni-ai-service
*/

/*  国产大模型 minimax 注册地址：https://platform.minimaxi.com/ */
const provider = 'minimax';
const apiKey =
	'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJHcm91cE5hbWUiOiLmtbflj6Pnvo7lhbDml6Dlt7Tlk6Xkv6Hmga_lkqjor6LmnI3liqHpg6giLCJVc2VyTmFtZSI6IuWtlOW-t-WBpSIsIkFjY291bnQiOiIiLCJTdWJqZWN0SUQiOiIxNjk1NTIxMTk5NDc2NTc4IiwiUGhvbmUiOiIiLCJHcm91cElEIjoiMTY5NTUyMTE5OTY0OTc2MSIsIlBhZ2VOYW1lIjoiIiwiTWFpbCI6ImlzY29vbGV5ZUAxNjMuY29tIiwiQ3JlYXRlVGltZSI6IjIwMjQtMTEtMTQgMTQ6NDQ6MjciLCJpc3MiOiJtaW5pbWF4In0.Jgjm_iMyczkZEWeM5S_SKG9u5cmP1xgvNmgzGC5jXW2oAFjPUkEBBBUcIf7vGo4RIF_9lALkUblQ7s8yAiXz5dc9qzueziFMhQN9q3MYacsvgVf3J4fWGDIaZ8JQL36iLYfca1C5qG0RKAiG2ENAQjYvGDf5u0pPIlGlt7A1bE0Lii3z1mGufq8hoLYwJFkB6oj3SSPPFJmLHSYFtC2ssaNo5gDWs1P8isBwPbRb4k14b9vNWRb1imQN25jgjbJIeBdAZsT2eRiADSBA7aq9R0Xh3o6IpufPjUc3ZyPKv_C04E_VTr25zYir0NLQBbBydN2lmvVdzN52nMXiMJfJTQ'
const groupId = '1695521199649761'

/* openai 如果想其使用chatgpt，就把上面的minimax注释，把此处放开 */
// const openai_provider = 'openai'
// const openai_apikey = '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';
// const proxy = "https://api.openai-proxy.com"

exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)

	const llmManager = uniCloud.ai.getLLMManager({
		provider: provider,
		apiKey: apiKey,
		groupId: groupId // minimax 需要，其他大模型不需要
	})

	const {
		thing
	} = event.prompt;

	const res = await llmManager.chatCompletion({
		messages: [{
				role: "system",
				content: `请根据输入的[物体],判断是什么垃圾类别。
				类别包括：可回收物、有害垃圾、湿垃圾、干垃圾。
				1、有害垃圾有：废镍镉电池和废氧化汞电池、废荧光灯管、废药品及其包装物、废油漆和溶剂及其包装物等；
				2、湿垃圾有：食材废料、剩菜剩饭、过期食品、瓜皮果核等；
				3、可回收物有：废纸张、废塑料、废玻璃制品、废金属等；
				4、干垃圾有：除三种类别外的垃圾，类别分辨不清的垃圾等。
				结果只需要回复“垃圾类别”即可，不要擅自回复额外的内容。
				`
			},
			{
				role: "user",
				content: `餐巾纸`
			},
			{
				role: "assistant",
				content: `干垃圾`
			},

			{
				role: "user",
				content: `玻璃瓶`
			},
			{
				role: "assistant",
				content: `可回收物`
			},

			{
				role: "user",
				content: `火锅汤底`
			},
			{
				role: "assistant",
				content: `湿垃圾`
			},
			{
				role: "user",
				content: thing
			},

		],
		tokensToGenerate: 1024,
	})

	//返回数据给客户端
	return res
};